package com.ls.pattern.behavior.observer;

import java.util.ArrayList;

public class WeatherData implements Subject {
    private float f1;
    private float f2;

    private ArrayList<Observer> observers;

    public WeatherData() {
        this.observers = new ArrayList();
    }

    public float getF1() {
        return f1;
    }

    public void setF1(float f1) {
        this.f1 = f1;
    }

    public float getF2() {
        return f2;
    }

    public void setF2(float f2) {
        this.f2 = f2;
    }

    public void setData(float f1, float f2) {
        this.f1 = f1;
        this.f2 = f2;
        dataChange();
    }

    public void dataChange() {
        notifyObserver();

    }

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void remove(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObserver() {
        for (Observer observer : observers) {
            observer.update(this.f1, this.f2);
        }
    }
}
